package com.stx.day0911;

import java.util.Arrays;

/**
 * packageName com.stx.day0911
 *
 * @author YangYi
 * @className BubbleSort
 * @date 2025/9/11
 * @description TODO
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arrays = {9, 45, 8, 23, 56, 4, 21, 18, 3};
        System.out.println(Arrays.toString(arrays));
//        for(int i =0;i<arrays.length;i++){
//            System.out.println(arrays[i]);
//        }
        bubbleSortMethod(arrays);
        int[] dest = new int[4];
        System.arraycopy(arrays, 1, dest, 1, 3);
        System.out.println(Arrays.toString(dest));
        int count = Arrays.binarySearch(arrays, 23);
        System.out.println(count);
    }

    /**
     * 冒泡排序
     *
     * @param arrays
     */
    public static void bubbleSortMethod(int[] arrays) {
        for (int i = 0; i < arrays.length - 1; i++) {
            for (int j = 0; j < arrays.length - i - 1; j++) {
                if (arrays[j] > arrays[j + 1]) {
                    int temp = arrays[j];
                    arrays[j] = arrays[j + 1];
                    arrays[j + 1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arrays));
    }
}
